<template>
    <div>
        <bi-table :data="list" :loading="loading" min-height="200">
            <bi-table-column label="类型" name="type" width="50"></bi-table-column>
            <bi-table-column label="标题" name="title" width="150"></bi-table-column>
            <bi-table-column label="名称" name="name" min-width="200"></bi-table-column>
            <bi-table-column label="操作" width="100px" v-slot="scope">
                <bi-button  type="warning" @click="del(scope.row)">删除</bi-button>
            </bi-table-column>
        </bi-table>
        <div class="button-list" style="padding-top: 20px;">
            <bi-button icon="fa-plus" type="light" @click="add" >添加插件</bi-button>
            <bi-button icon="fa-refresh" type="light" @click="update" >更新</bi-button>
        </div>
    </div>
</template>

<script>
import addPlugDialog from 'add-plug-dialog.vue';

export default{
    data(){
        return {
            list:[],
            loading:false
        }
    },
    methods:{
        getList(){
            this.loading = true;
            this.$ajax({
                url:this.$url({controller:'plug',action:'list'}),
                data:{
                    app:this.app
                },
                success:(data)=>{
                    this.list = data;
                },
                over:()=>{
                    this.loading = false;
                }
            })
        },
        add(){
            this.$dialog({
                type:'vue',
                content:admin.createApp(addPlugDialog,{app:this.app}),
                callback:()=>{
                    this.getList();
                }
            })
        },
        update(){
            this.loading = true;
            this.$ajax({
                url:this.$url({controller:'plug',action:'update'}),
                data:{
                    app:this.app
                },
                success:(data)=>{
                    this.$toast('更新成功');
                    this.getList();
                },
                over:()=>{
                    this.loading = false;
                }
            })
        },
        sync(){
            this.loading = true;
            this.$ajax({
                url:this.$url({controller:'plug',action:'sync'}),
                data:{
                    app:this.app
                },
                success:(data)=>{
                    this.$toast('同步成功');
                    this.getList();
                },
                over:()=>{
                    this.loading = false;
                }
            })
        },
        del(row){
            this.$confirm('确定要删除吗?',()=>{
                this.$ajax({
                    url:this.$url({controller:'plug',action:'del'}),
                    data:{
                        app:this.app,
                        name:row.name
                    },
                    success:()=>{
                        this.$toast('删除成功');
                        this.getList();
                    }
                })
            });
        }
    },
    props:{
        app:String
    },
    mounted(){
        this.getList();
    }
}
</script>